import { login } from '../../api/admin'

export default {
  loginAction(values) {
    return (dispatch) => {
      return new Promise((resolve, reject) => {
        login(values).then(res => {
          if(res.data.code === '10008') {
            reject()
          } else {
            dispatch({ type: 'CHANGE_ADMIN_NAME', payload: res.data.data.adminname})
            dispatch({ type: 'CHANGE_ROLE', payload: res.data.data.role})
            dispatch({ type: 'CHANGE_TOKEN', payload: res.data.data.token})
            dispatch({ type: 'CHANGE_LOGIN_STATE', payload: true})
            resolve(res)
          }
        })
      })
    }
  }
}